package com.applications.addressbookapp;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class SearchContact extends ListActivity{
	
	 EditText searchName;	
	 ListView listView;
	 DBTools dbTools = new DBTools(this);
	 public void onCreate(Bundle savedInstanceState) {
		 
	        // Get saved data if there is any
	 
	        super.onCreate(savedInstanceState);
	 
            setContentView(R.layout.search_contact);
            listView = getListView();
	        searchName = (EditText)findViewById(R.id.SearchName);	 
	    }
	 
	 public void searchContact(View view) {
		 
		 String searchContact;
		 searchContact = searchName.getText().toString();
		 if (searchContact== null) 
			 return;
		 
		 ArrayList<HashMap<String, String>> searchContactList =  dbTools.getSearchContacts(searchContact);
		 
		 if (searchContactList.size()==0) 
			 return;
		 
		 ListAdapter adapter = new SimpleAdapter(SearchContact.this, searchContactList, R.layout.search_entry, 
					new String[]{"contactId", "lastName","lastName"},
					new int[]{R.id.searchcontactId,R.id.searchlastName,R.id.searchfirstName});

		 setListAdapter(adapter);

	 }
		 
 }
